package com.hdu.clj.fitness

import android.content.Context
import java.io.*

class LoadAndSave {
    fun load(data:String,context: Context): String {
        val content = StringBuilder()

        try {
            val input = context.openFileInput(data)
            val reader = BufferedReader(InputStreamReader(input))
            reader.use {
                reader.forEachLine {
                    content.append(it)
                }
            }
        }catch (e: IOException){
            e.printStackTrace()
        }
        return content.toString()
    }

    fun save(inputText: String,data:String,context: Context) {
        try {
            val output = context.openFileOutput(data, Context.MODE_PRIVATE)
            val writer = BufferedWriter(OutputStreamWriter(output))
            writer.use {
                it.write(inputText)
            }
        }catch (e: IOException){
            e.printStackTrace()
        }
    }
}